const MYSQL = require("../../sql/mysql");
const MYSQLConfig = require("../../sql/database");
const SQLName = MYSQLConfig.datasheetName.user_token;
/**
 * 删除用户的所有token
 * @param {object} params
 * @param {string} params.user 用户id
 * @return {Promise<{code:number,msg:string} | {code:number,msg:string}>}
 */
module.exports = async (params = {}) => {
  try {
    let { user } = params;
    if (!user) {
      throw { code: 500, msg: "user 不能为空" };
    }
    let query = `DELETE FROM ${SQLName} WHERE user = '${user}'`;
    await MYSQL.promise().query(query);
    return { code: 0, msg: "操作成功" };
  } catch (error) {
    throw { code: 500, msg: "操作失败，服务器更新错误" };
  }
};
